//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateBulletin {
        private readonly IBulletinRepository _bulletinRepository;

        public CreateBulletin(IBulletinRepository bulletinRepository) {
            _bulletinRepository = bulletinRepository;
        }

        public void Execute(Guid userId, ICreateBulletinCommand bulletinForm) {
            if (bulletinForm == null)
                throw new ArgumentNullException("bulletinForm");

            try {
                var bulletin = bulletinForm.ConvertToEntity();
                _bulletinRepository.Create(bulletin);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
